package com.school.admin.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.school.admin.entity.MallSysPurview;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.school.admin.entity.vo.PurviewVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 接口权限表 Mapper 接口
 * </p>
 *
 * @author sunpx
 * @since 2022-03-24
 */
public interface MallSysPurviewMapper extends BaseMapper<MallSysPurview> {


    /**
     * 查询接口所需角色
     * @author : sunpx
     * @param
     * @return java.util.List<com.school.admin.entity.vo.PurviewVo>
     * @date : 2022-03-24 17:11:37
     */
    @Select("select t3.address, group_concat(t2.role_id) role_names\n" +
            "from      mall_sys_purview_role t2 \n" +
            "         inner join mall_sys_purview t3 on t2.purview_id = t3.id\n" +
            "group by address")
    List<PurviewVo> getAllPurviewRoles();


    /**
     * 全量信息
     * @author : sunpx
     * @param
     * @return java.util.List<com.school.admin.entity.vo.PurviewVo>
     * @date : 2022-03-24 17:11:37
     */
    Page<PurviewVo> getAllPurviewRolesAll(Page page,@Param("purviewVo") PurviewVo purviewVo);


    /**
     * 查询角色权限
     * @author : sunpx
     * @param rid 角色id
     * @return java.util.List<com.school.admin.entity.vo.PurviewVo>
     * @date : 2022-04-16 13:40:23
     */
    @Select("select distinct t1.id, t1.purview_url, t1.purview_name, if(t2.purview_id is null ,0,1) is_belong\n" +
            "from mall_sys_purview t1\n" +
            "         left join mall_sys_purview_role t2 on t1.id = t2.purview_id and t2.role_id = #{rid} \n"
            )
    List<PurviewVo> queryRolePurview(@Param("rid") String rid);
}
